<?php

namespace App\Http\Controllers;

use App\Models\Goods;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use XS;

class TestController extends Controller
{
    //
    public function index()
    {
        $k = '';
        $xs = new XS(config_path('Xunsearch.ini'));
        $search = $xs->search;
        $search->setQuery($k);
        $docs = $search->search();
        dd($docs);
    }

    public function add()
    {
        $xs = new XS(config_path('Xunsearch.ini'));

        $xs->index->openBuffer();//开启索引缓存
        $doc = new \XSDocument();
        $doc->setFields([
            'pid' => 4,
            'goods_name' => '连衣裙女夏学生可爱小清新套装裙韩版宽松百搭中长款两件套网纱裙',
            'shop_name' => '耳环旗舰店',
            'chrono' => time(),
        ]); // 用数组进行批量赋值
        $xs->index->add($doc);

        $xs->index->closeBuffer();//关闭索引缓存

        dd('ok');
    }

    public function del()
    {
//        $del = ['1','3'];
        $xs = new XS(config_path('Xunsearch.ini'));
//        $xs->index->del();
//        dd('ok');
        $xs->index->clean();
        dd('ok');
    }


    public function unq()
    {
//        $goods = Goods::whereIn('goods_id',['521246796347'])->get();
        //查询数据库中相同值的id
//        SELECT * FROM people WHERE peopleId IN ( SELECT peopleId FROM people GROUP BY peopleId HAVING count(peopleId) > 1 )

        //删除数据库相同的值 留下最小的
//        DELETE FROM people WHERE peopleName IN ( SELECT peopleName FROM people GROUP BY peopleName HAVING count(peopleName) > 1 ) AND peopleId NOT IN ( SELECT max(peopleId) FROM people GROUP BY peopleName HAVING count(peopleName) > 1 )
//        dd($goods);
    }


}
